import axios from 'axios'
import { Toast } from 'vant'
// axios.defaults.baseURL = process.env.VUE_APP_URL
const _fetch = axios.create({
  baseURL: process.env.VUE_APP_URL
})
_fetch.interceptors.request.use(
  function (congfig) {
    return congfig
  },
  function (error) {
    return Promise.reject(error)
  }
)
_fetch.interceptors.response.use(
  function (res) {
    if (res.data.code === 200) {
      return res
    } else {
      Toast.fail(res.data.message)
      return Promise.reject(new Error('error'))
    }
  },
  function (error) {
    return Promise.reject(error)
  }
)
// Vue.prototype.$axios = axios
export default _fetch
